home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / dpmigcc5.zip / RSX / SOURCE / ASM16 / ADOSX32.ASM next >
Assembly Source File  |  1994-12-12  |  8KB  |  356 lines

  1. ;
  2. ; ADOSX32.ASM (c) Rainer Schnitker 92,93
  3. ;
  4. ; Entry point for protected mode int 0x21
  5. ;
  6.  
  7.     INCLUDE REGS386.INC
  8.     INCLUDE TRANS.INC
  9.  
  10.     .386p
  11.  
  12. DGROUP group _DATA
  13.  
  14. IFDEF    __WASM__
  15.     INT21        equ int21_
  16.     CHECK_SIGNALS    equ check_signals_
  17.     MYEXCEP13    equ myexcep13_
  18.     extrn int21_:near        ; C-function int21 handler
  19.     extrn check_signals_:near    ; C-func:check if signals raised
  20.     extrn myexcep13_:near        ; C-func:exception hander
  21. ELSE
  22.     INT21        equ _int21
  23.     CHECK_SIGNALS    equ _check_signals
  24.     MYEXCEP13    equ _myexcep13
  25.     extrn _int21:near        ; C-function int21 handler
  26.     extrn _check_signals:near    ; C-func:check if signals raised
  27.     extrn _myexcep13:near        ; C-func:exception hander
  28. ENDIF
  29.  
  30.     extrn _load_ds:near        ; load 16bit extender ds
  31.     extrn _clearregs:near        ; clear high bits from 32bit regs
  32.  
  33. _DATA segment word public 'DATA' use16
  34.     extrn _npz:PROCESS        ; pointer to running process
  35.     extrn _regf:REG386        ; regs for exceptions
  36.     extrn _cs16real: word        ; RM cs segment
  37.     extrn _ds16real: word        ; RM ds segment
  38.     extrn _real_mode_stack: word    ; RM stack pointer
  39.     td TRANS  <>            ; translation struct for dos
  40. _DATA ends
  41.  
  42. _TEXT segment word public 'CODE' use16
  43.     assume cs:_TEXT,ds:DGROUP
  44.  
  45.  
  46. ; ***************************************
  47.  
  48. ; Entry point for int 0x10
  49.  
  50. public _bioscall
  51. _bioscall proc far            ; INT 0x10 handler entry
  52.  
  53. not_vesa:
  54.                     ; jmp to orginal handler (DPMI-host)
  55.     db 066h     ; 32bit
  56.     db 0EAh     ; JMP
  57. public _int10voff            ; label for writing in code
  58. _int10voff:
  59.     dd 2        ; offset
  60. public _int10vsel            ; label for writing in code
  61. _int10vsel:
  62.     dd 1        ; selector
  63.  
  64. _bioscall endp
  65.  
  66.  
  67. ; **************************************
  68.  
  69. public _mousecall
  70. _mousecall proc far             ; INT 0x33 handler entry
  71.     iret
  72. _mousecall endp
  73.  
  74. ; **************************************
  75. ; Entry point for int 0x21
  76. ; - test default bit from code segment ( 32 or 16 bit )
  77. ; - we handle only 32bit-calls
  78. ; - all 16bit calls (from our extender) passed to real mode
  79. ;   only segment registers are changed
  80. ;
  81.  
  82. public _doscall
  83. _doscall proc far            ; INT 0x21 handler entry
  84.     push    eax
  85.     mov    ax, cs            ; KERNEL_CS == CS ?
  86.     cmp    [esp+8], ax        ; 0:eax,4:eip,8:cs,12:eflags
  87.     pop    eax
  88.  
  89.     je    short int16bit        ; 16bit DOS call from extender
  90.  
  91.     cmp    ah, 04Ch        ; exit call ?
  92.     jne    int32bit        ; no, must 32bit user int
  93.  
  94.     ; ah=4Ch: recursive extender instance or 32bit user call ?
  95.     ; next instance reset interrupt handler and do int21/0x4c00
  96.  
  97.     push    eax
  98.     push    si
  99.     push    ds
  100.     call    _load_ds            ; load 16 bit extender ds
  101.     mov    si, word ptr _npz        ; load process ptr
  102.     mov    eax, [esp+12]            ; 0:eax,4:si,ds,8:eip,12:cs
  103.     cmp    ax, word ptr [si].r_cs
  104.     pop    ds
  105.     pop    si
  106.     pop    eax
  107.     je    short int32bit
  108.  
  109.                     ; jmp to orginal handler (DPMI-host)
  110.     db 066h     ; 32bit
  111.     db 0EAh     ; JMP
  112. public _int21voff            ; label for writing in code
  113. _int21voff:
  114.     dd 2        ; offset
  115. public _int21vsel            ; label for writing in code
  116. _int21vsel:
  117.     dd 1        ; selector
  118.  
  119.  
  120.  
  121. ; **************************************
  122. ; all 16bit calls assume that this call is equal to a real mode call
  123. ; where the segment registers are equal to programs segments
  124. ;
  125. ; stack: 0=eip 4=cs 8=eflags
  126.  
  127. int16bit:
  128.     mov    word ptr td.T_EAX, ax           ; save registers
  129.     mov    word ptr td.T_EBX, bx
  130.     mov    word ptr td.T_ECX, cx
  131.     mov    word ptr td.T_EDX, dx
  132.     mov    word ptr td.T_ESI, si
  133.     mov    word ptr td.T_EDI, di
  134.     mov    word ptr td.T_EBP, bp
  135.     mov    ax, _cs16real            ; set RM segments
  136.     mov    word ptr td.T_CS, ax
  137.     mov    ax, _ds16real
  138.     mov    word ptr td.T_DS, ax
  139.     mov    word ptr td.T_ES, ax
  140.     mov    word ptr td.T_SS, ax
  141.     mov    ax, _real_mode_stack        ; stack for int
  142.     mov    word ptr td.T_sp, ax
  143.  
  144.     push    ds                ; DPMI call now
  145.     pop    es
  146.     mov    cx, 0                ; no stack words
  147.     mov    bh, 0                ; flags
  148.     mov    bl, 21h             ; interrupt no
  149.     xor    edi, edi            ;
  150.     mov    di, offset DGROUP:td        ; es:edi translation
  151.     mov    ax, 0300h
  152.     int    31h                ; simulate real-mode int
  153.  
  154.     movzx    ebp, sp
  155.     mov    ax, word ptr td.T_FLAGS     ; trans -> registers
  156.     mov    word ptr [bp+8], ax
  157.     mov    ax, word ptr td.T_EAX
  158.     mov    bx, word ptr td.T_EBX
  159.     mov    cx, word ptr td.T_ECX
  160.     mov    dx, word ptr td.T_EDX
  161.     mov    si, word ptr td.T_ESI
  162.     mov    di, word ptr td.T_EDI
  163.     mov    bp, word ptr td.T_EBP
  164.     iretd
  165.  
  166.  
  167. ; **************************************
  168. ; here is the 32bit handler
  169. ; save all registers, check signals, restore all registers
  170.  
  171. int32bit:      ; stack: 0=eip 4=cs 8=eflags
  172.  
  173.     push    esi
  174.     call    _load_ds            ; load 16 bit extender ds
  175.     xor    esi, esi
  176.     mov    si, word ptr DGROUP:_npz    ; load process ptr
  177.     pop    dword ptr [si].r_esi        ; save ESI
  178.  
  179.     mov    [si].r_eax, eax         ; EAX
  180.     mov    [si].r_ebx, ebx         ; EBX
  181.     mov    [si].r_ecx, ecx         ; ECX
  182.     mov    [si].r_edx, edx         ; EDX
  183.     mov    [si].r_edi, edi         ; EDI
  184.     mov    [si].r_ebp, ebp         ; EBP
  185.     mov    word ptr [si].r_ds, es        ; DS
  186.     mov    word ptr [si].r_es, es        ; ES    !assume(es=ds)
  187.     mov    word ptr [si].r_ss, ss        ; SS
  188.     mov    word ptr [si].r_fs, fs        ; FS
  189.     mov    word ptr [si].r_gs, gs        ; GS
  190.     mov    [si].r_esp, esp         ; ESP
  191.     mov    [si].r_esporg, esp        ; ESP before int
  192.     add    [si].r_esporg, dword ptr 12    ;
  193.  
  194.     mov    ebp, esp            ; others regs are on user stack
  195.     mov    eax, [ebp]            ; EIP
  196.     mov    [si].r_eip, eax
  197.     mov    eax, [ebp+4]            ; CS
  198.     mov    [si].r_cs, eax
  199.     mov    eax, [ebp+8]            ; EFLAGS
  200.     mov    [si].r_eflags, eax
  201.  
  202.     mov    ax, ds                ; make ss=ds=es
  203.     mov    es, ax                ; load 16bit es
  204.     mov    ss, ax                ; load 16bit ss
  205.     mov    esp, [si].kstack        ; load 16bit sp
  206.  
  207.     call    _clearregs    ; clear high bits for our 16bit prg
  208.  
  209.     call    INT21        ; call C-prg handler for int21h
  210.  
  211. public _back_from_syscall
  212. _back_from_syscall:
  213.     call    CHECK_SIGNALS
  214.  
  215.     mov    si, word ptr DGROUP:_npz    ; load process ptr
  216.     mov    ebx, [si].r_ebx         ; restore old regs
  217.     mov    ecx, [si].r_ecx
  218.     mov    edx, [si].r_edx
  219.     mov    edi, [si].r_edi
  220.     mov    ebp, [si].r_ebp
  221.     mov    ss , word ptr [si].r_ss     ; change ss first
  222.     mov    esp, [si].r_esp         ; restore ss:esp
  223.     mov    es , word ptr [si].r_es
  224.     mov    fs , word ptr [si].r_fs
  225.     mov    gs , word ptr [si].r_gs
  226.  
  227.     mov    eax, [si].r_eflags        ; other regs are on user stack
  228.     mov    [esp+8], eax
  229.     mov    eax, [si].r_cs
  230.     mov    [esp+4], eax
  231.     mov    eax, [si].r_eip
  232.     mov    [esp], eax
  233.     mov    eax, [si].r_eax         ; eax
  234.  
  235.     push    dword ptr [si].r_esi        ; restore esi
  236.     pop    esi
  237.  
  238.     push    es
  239.     pop    ds                ; last segment restore
  240.     iretd
  241. _doscall endp
  242.  
  243.  
  244. public _debug_entry
  245. _debug_entry proc far
  246.     push    ds
  247.     call    _load_ds
  248.  
  249.     mov    dword ptr DGROUP:_regf.REG_EAX, eax
  250.     mov    dword ptr DGROUP:_regf.REG_EBX, ebx
  251.     mov    dword ptr DGROUP:_regf.REG_ECX, ecx
  252.     mov    dword ptr DGROUP:_regf.REG_EDX, edx
  253.     mov    dword ptr DGROUP:_regf.REG_EBP, ebp
  254.     mov    dword ptr DGROUP:_regf.REG_EDI, edi
  255.     mov    dword ptr DGROUP:_regf.REG_ESI, esi
  256.     mov    word ptr DGROUP:_regf.REG_ES , es
  257.     mov    word ptr DGROUP:_regf.REG_SS , ss
  258.     mov    word ptr DGROUP:_regf.REG_FS , fs
  259.     mov    word ptr DGROUP:_regf.REG_GS , gs
  260.     pop    ax
  261.     mov    word ptr DGROUP:_regf.REG_DS, ax
  262.  
  263.     mov    dword ptr DGROUP:_regf.REG_ESP, esp
  264.     add    dword ptr DGROUP:_regf.REG_ESP, 12
  265.     mov    dword ptr DGROUP:_regf.REG_ESPORG, esp
  266.     add    dword ptr DGROUP:_regf.REG_ESPORG, 12
  267.     mov    word ptr DGROUP:_regf.REG_FAULTNO, 3
  268.  
  269.     mov    ebp, esp            ; others regs are on user stack
  270.     mov    eax, [ebp]            ; EIP
  271.     mov    dword ptr DGROUP:_regf.REG_EIP, eax
  272.     mov    eax, [ebp+4]            ; CS
  273.     mov    dword ptr DGROUP:_regf.REG_CS, eax
  274.     mov    eax, [ebp+8]            ; EFLAGS
  275.     mov    dword ptr DGROUP:_regf.REG_EFLAGS, eax
  276.  
  277.     mov    si, word ptr DGROUP:_npz    ; load process ptr
  278.     mov    edx, [si].kstack
  279.     mov    ax, ds                ; make ss=ds=es
  280.     mov    es, ax                ; load 16bit es
  281.     mov    ss, ax                ; load 16bit ss
  282.     mov    esp, edx            ; load 16bit sp
  283.  
  284.     call    _clearregs
  285.     call    MYEXCEP13
  286.  
  287.     jmp    _back_from_syscall
  288. _debug_entry endp
  289.  
  290.  
  291. public _execute_dpmi_function
  292. _execute_dpmi_function proc near
  293.     pushad
  294.     push    ds
  295.     push    es
  296.  
  297.     mov    si, word ptr DGROUP:_npz    ; load process ptr
  298.     mov    eax, [si].r_eax
  299.     mov    ebx, [si].r_ebx
  300.     mov    ecx, [si].r_ecx
  301.     mov    edx, [si].r_edx
  302.     mov    ebp, [si].r_ebp
  303.     mov    edi, [si].r_edi
  304.     push    word ptr [si].r_ds
  305.     push    word ptr [si].r_es
  306.     mov    esi, [si].r_esi
  307.     pop    es
  308.     pop    ds
  309.     int    031h
  310.  
  311.     pop    es
  312.     pop    ds
  313.     popad
  314.     nop
  315.  
  316.     pushf                    ; save carry
  317.     pop    ax
  318.     and    ax, 1
  319.     ret
  320. _execute_dpmi_function endp
  321.  
  322.  
  323. public _save_all
  324. _save_all proc near
  325.     push    bp
  326.     mov    bp, sp
  327.     mov    bx, word ptr [bp+4]
  328.     pusha
  329.     mov    [bx], sp
  330.     leave
  331.     ret
  332. _save_all endp
  333.  
  334. public _restore_all
  335. _restore_all proc near
  336.     push    bp
  337.     mov    bp, sp
  338.     mov    bx, word ptr [bp+4]
  339.     mov    sp, [bx]
  340.     popa
  341.     leave
  342.     ret
  343. _restore_all endp
  344.  
  345. public _new_stack_return
  346. _new_stack_return proc near
  347.     mov    bp, sp
  348.     mov    bx, word ptr [bp+2]
  349.     mov    sp, [bx]
  350.     jmp    _back_from_syscall
  351. _new_stack_return endp
  352.  
  353. _TEXT    ends
  354.  
  355.     end
  356.